﻿using System;
using System.ComponentModel.Design;
using System.Security.Cryptography.X509Certificates;

namespace Lesson13_练习题
{
    #region 练习题一
    //写一个Monster类 它派生出Boss和Goblin两个类
    //Boss可以使用技能 GoBlin可以攻击
    //随机生成10个怪物 使用数组作为容器
    //遍历这个数组 调用攻击方法
    class Monster
    {

    }
    class Boss : Monster
    {
        public void BossSkill()
        {
            Console.WriteLine("Boss使用技能");
        }
    }
    class Goblin : Monster
    {
        public void GoblinAtk()
        {
            Console.WriteLine("Goblin攻击");
        }
    }
    #endregion

    #region 练习二
    //写一个玩家类 玩家可以拥有各种武器
    //现有四种武器 冲锋枪、霰弹枪、手枪、匕首
    //玩家默认拥有匕首
    //在玩家类中写一个方法、可以拾取武器替换现有武器
    class Weapon
    {

    }
    class SubmachineGun : Weapon
    {
        
    }
    class ShotGun : Weapon
    {

    }
    class Pistol : Weapon
    {

    }
    class Dagger : Weapon
    {

    }

    class Player
    {
        private Weapon nowWeapon;
        public Player()
        {
            nowWeapon = new Dagger();
        }
        public void PickUpWeapon(Weapon puWeapon)
        {
            nowWeapon = puWeapon;
        }
        public void CheckNowWeapon()
        {
            if (nowWeapon is SubmachineGun)
            {
                Console.WriteLine("持有冲锋枪");
            }
            else if (nowWeapon is ShotGun)
            {
                Console.WriteLine("持有霰弹枪");
            }
            else if (nowWeapon is Pistol)
            {
                Console.WriteLine("持有手枪");
            }
            else
            {
                Console.WriteLine("持有匕首");
            }
        }
    }
    #endregion

    class Program
    {
        static void Main(string[] args)
        {
            #region 练习一
            Monster[] monsters = new Monster[10];
            Random random = new Random();
            //随机10个怪物
            for (int i = 0; i < monsters.LongLength; i++)
            {
                int rNum = random.Next(1, 101);
                if( rNum <= 50)
                {
                    monsters[i] = new Boss();
                }
                else
                {
                    monsters[i] = new Goblin();
                }
            }
            //遍历调用攻击方法
            for (int i = 0; i < monsters.LongLength; i++)
            {
                if (monsters[i] is Boss)
                {
                    (monsters[i] as Boss).BossSkill();
                }
                else
                {
                    (monsters[i] as Goblin).GoblinAtk();
                }
            }
            #endregion

            Console.WriteLine("********************");
            
            #region 练习二
            Player player = new Player();
            SubmachineGun s1 = new SubmachineGun();
            ShotGun s2 = new ShotGun();
            Pistol p1 = new Pistol();
            Dagger d1 = new Dagger();
            player.PickUpWeapon(s1);
            player.CheckNowWeapon();
            player.PickUpWeapon(s2);
            player.CheckNowWeapon();
            player.PickUpWeapon(p1);
            player.CheckNowWeapon();
            player.PickUpWeapon(d1);
            player.CheckNowWeapon();
            #endregion
        }
    }
}